//
//  GYStatusRetweetView.swift
//  Weibo
//
//  Created by vane on 16/8/13.
//  Copyright © 2016年 apple. All rights reserved.
//

import UIKit
import SnapKit

class GYStatusRetweetView: UIView {
    
    var retweetViewBottomConstraint: Constraint?
    
    var statusViewModel: GYStatusViewModel?{
        didSet{
        
            contentLabel.text = statusViewModel?.statusModel?.retweeted_status?.text
            
            retweetViewBottomConstraint?.uninstall()
            
            if statusViewModel?.statusModel?.retweeted_status?.pic_urls?.count > 0 {
                
                pictureView.pictureInfos = statusViewModel?.statusModel?.retweeted_status?.pic_urls
                
                self.snp_makeConstraints { (make) -> Void in
                    retweetViewBottomConstraint = make.bottom.equalTo(pictureView).offset(10).constraint
                }
                
                pictureView.hidden = false
            }else {
                
                self.snp_makeConstraints { (make) -> Void in
                    retweetViewBottomConstraint = make.bottom.equalTo(contentLabel).offset(10).constraint
                }
                
                pictureView.hidden = true
            }

            
            
            
        }
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func setupUI(){
        
        backgroundColor = RGB(237, green: 237, blue: 237)
        
        addSubview(contentLabel)
        addSubview(pictureView)


        contentLabel.snp_makeConstraints { (make) -> Void in
            make.leading.top.equalTo(10)
        }
        pictureView.snp_makeConstraints { (make) -> Void in
            
            make.top.equalTo(contentLabel.snp_bottom).offset(10)
            make.leading.equalTo((SCREENW - 250)/2)
          
        }
        self.snp_makeConstraints { (make) -> Void in
            
           retweetViewBottomConstraint = make.bottom.equalTo(pictureView).offset(10).constraint
        }
        
    }
    
    private lazy var contentLabel: UILabel = UILabel(textColor: UIColor.darkGrayColor(), textSize: 15, maxWidth: SCREENW - 20)
    
    private lazy var pictureView:GYStatusPictureView = GYStatusPictureView()

}
